package com.gxsyh.nantie.statements.management.provider.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.gxsyh.nantie.commons.dto.PageHelpDTO;
import com.gxsyh.nantie.commons.dto.ResponseResult;
import com.gxsyh.nantie.statements.management.provider.domain.ApartmentOrderInfo;
import com.gxsyh.nantie.statements.management.provider.domain.ApartmentStatements;
import com.gxsyh.nantie.statements.management.provider.service.ApartmentOrderInfoService;
import com.gxsyh.nantie.statements.management.provider.service.ApartmentStatementsService;
import com.gxsyh.nantie.statements.management.provider.service.TbOrderService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
public class ApartmentStatementsController {

    @Resource
    private ApartmentStatementsService apartmentStatementsService;

    @Resource
    private TbOrderService tbOrderService;

    @Resource
    private ApartmentOrderInfoService apartmentOrderInfoService;


    /**
     * 获取 中心公寓报表 财务列表
     * @param pageNum,apartmentId
     * @return
     */
    @GetMapping(value = "/statements/apartment/list/{pageNum}")
    public ResponseResult<PageHelpDTO> apartmentList(@PathVariable int pageNum,@RequestParam long apartmentId){
        PageHelper.startPage(pageNum,5);
        PageInfo<ApartmentStatements> pageInfo=new PageInfo<>(apartmentStatementsService.selectApartmentStatements(apartmentId));
        List<ApartmentStatements> apartmentStatementsList = pageInfo.getList();
        PageHelpDTO pageHelpDTO=new PageHelpDTO();
        pageHelpDTO.setPages(pageInfo.getPages());
        pageHelpDTO.setTotal(pageInfo.getTotal());
        pageHelpDTO.setData(apartmentStatementsList);
        return new ResponseResult<>(200,"中心公寓报表",pageHelpDTO);
    }


    /**
     * 获取 次级公寓报表 列表
     * @param pageNum,apartmentId
     * @return
     */
    @GetMapping(value = "/statements/apartment/subordinate/list/{pageNum}")
    public ResponseResult<PageHelpDTO> apartmentStatementsList(@PathVariable int pageNum,@RequestParam long apartmentId ){
        PageHelper.startPage(pageNum,5);
        PageInfo<ApartmentStatements> pageInfo=new PageInfo<>(apartmentStatementsService.selectSubordinateApartmentStatements(apartmentId,apartmentId));
        List<ApartmentStatements> apartmentStatementsList = pageInfo.getList();
        PageHelpDTO pageHelpDTO=new PageHelpDTO();
        pageHelpDTO.setPages(pageInfo.getPages());
        pageHelpDTO.setTotal(pageInfo.getTotal());
        pageHelpDTO.setData(apartmentStatementsList);
        return new ResponseResult<>(200,"次级公寓报表",pageHelpDTO);
    }

    /**
     * 获取 公寓订单 列表
     * @param pageNum,apartmentId
     * @return
     */
    @GetMapping(value = "/statements/apartment/list/info/{pageNum}")
    public ResponseResult<PageHelpDTO> apartmentStatementsListInfo(@PathVariable int pageNum,@RequestParam long apartmentId){
        PageHelper.startPage(pageNum,5,"tb_order.createTime DESC");
        PageInfo<ApartmentOrderInfo> pageInfo=new PageInfo<>(apartmentOrderInfoService.selectApartmentOrder(apartmentId));
        List<ApartmentOrderInfo> apartmentOrderInfoList = pageInfo.getList();
        PageHelpDTO pageHelpDTO=new PageHelpDTO();
        pageHelpDTO.setPages(pageInfo.getPages());
        pageHelpDTO.setTotal(pageInfo.getTotal());
        pageHelpDTO.setData(apartmentOrderInfoList);
        return new ResponseResult<>(200,"公寓订单列表",pageHelpDTO);
    }

    /**
     * 根据订单状态及公寓查询订单
     * @param pageNum,apartmentId
     * @return
     */
    @GetMapping(value = "/statements/apartment/list/orderstatus/{pageNum}")
    public ResponseResult<PageHelpDTO> findorderStatusByApartmentOrder(@PathVariable int pageNum,@RequestParam long apartmentId,@RequestParam Integer orderStatus){
        PageHelper.startPage(pageNum,5,"tb_order.createTime ASC");
        PageInfo<ApartmentOrderInfo> pageInfo=new PageInfo<>(apartmentOrderInfoService.findorderStatusByApartmentOrder(apartmentId,1,orderStatus));
        List<ApartmentOrderInfo> apartmentOrderInfoList = pageInfo.getList();
        PageHelpDTO pageHelpDTO=new PageHelpDTO();
        pageHelpDTO.setPages(pageInfo.getPages());
        pageHelpDTO.setTotal(pageInfo.getTotal());
        pageHelpDTO.setData(apartmentOrderInfoList);
        return new ResponseResult<>(200,"根据订单状态查询公寓订单",pageHelpDTO);
    }

    /**
     * 根据订单状态获取所有订单
     * @param pageNum,apartmentId
     * @return
     */
    @GetMapping(value = "/statements/apartment/list/allorder/{pageNum}")
    public ResponseResult<PageHelpDTO> findAllorderStatusByApartmentOrder(@PathVariable int pageNum,@RequestParam Integer orderStatus){
        PageHelper.startPage(pageNum,5,"tb_order.createTime ASC");
        PageInfo<ApartmentOrderInfo> pageInfo=new PageInfo<>(apartmentOrderInfoService.findAllorderStatusByApartmentOrder(1,orderStatus));
        List<ApartmentOrderInfo> apartmentOrderInfoList = pageInfo.getList();
        PageHelpDTO pageHelpDTO=new PageHelpDTO();
        pageHelpDTO.setPages(pageInfo.getPages());
        pageHelpDTO.setTotal(pageInfo.getTotal());
        pageHelpDTO.setData(apartmentOrderInfoList);
        return new ResponseResult<>(200,"根据订单状态获取所有订单",pageHelpDTO);
    }






}
